import instance from "./http";

/**
 * 封装 GET 请求
 * @param {string} url - 请求的 URL
 * @param {object} [params = {}] - 请求参数
 * @returns {Promise<any>} - 响应数据
 */
export async function get(url, params = {}, headers) {
    try {
        const response = await instance.get(url, { params, headers });
        return response;
    } catch (error) {
        console.error("GET request error:", error);
        throw error;
    }
}

export async function put(url, data) {
    try {
        const response = await instance.put(url, data);
        return response;
    } catch (error) {
        console.error("GET request error:", error);
        throw error;
    }
}

export async function del(url, params = {}) {
    try {
        const response = await instance.delete(url, { params });
        return response;
    } catch (error) {
        console.error("GET request error:", error);
        throw error;
    }
}

/**
 * 封装 POST 请求
 * @param {string} url - 请求的 URL
 * @param {object} [data = {}] - 请求数据
 * @returns {Promise<any>} - 响应数据
 */
export async function post(url, data = {}, headers) {
    try {
        const response = await instance.post(url, data, { headers });
        return response;
    } catch (error) {
        console.error("POST request error:", error);
        throw error;
    }
}